package com.dl.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class DBConnection {
    private String username = "root" ;

    private String password = "123456" ;

    private String url = "jdbc:mysql://localhost:3306/hotel?serverTimezone=UTC &&useSSL=false" ;

    private String driver = "com.mysql.jdbc.Driver" ;

    private Connection conn = null ;

    private PreparedStatement pstmt = null ;

    public Connection getConnection() {
        try {
            Class.forName(driver) ;
            this.conn = DriverManager.getConnection(url,username,password) ;
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return conn;
    }


    public void AllClose() {

        if(pstmt != null) {
            try {
                pstmt.close() ;
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        if(conn != null) {
            try {
                conn.close() ;
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
